package com.dongwu.manager.entity;

import com.dongwu.common.entity.BaseEntity;
import com.dongwu.security.entity.User;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.List;

/**
 * 模板类型
 * 
 * @author liangrs
 *
 */
@Entity
public class TemplateType extends BaseEntity<String> {

	private String templateTypeName; // 模板类型名称

	private String image; //模板图片
	
	private String templateTypeSn; //模板类别唯一编码
	
	private String isDel; //模板状态
	
	@ManyToMany(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.LAZY)
	@JoinTable(name = "template_type_user",
			joinColumns = {@JoinColumn(name = "template_type_id")},
			inverseJoinColumns = {@JoinColumn(name = "user_id")})
	@Fetch(value = FetchMode.SUBSELECT)
	private List<User> users = Lists.newArrayList();

	public String getTemplateTypeName() {
		return templateTypeName;
	}

	public void setTemplateTypeName(String templateTypeName) {
		this.templateTypeName = templateTypeName;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}
	

	public String getTemplateTypeSn() {
		return templateTypeSn;
	}

	public void setTemplateTypeSn(String templateTypeSn) {
		this.templateTypeSn = templateTypeSn;
	}

	public String getIsDel() {
		return isDel;
	}

	public void setIsDel(String isDel) {
		this.isDel = isDel;
	}

	@Transient
	public String getUserIds() {
		List<String> ids = Lists.newArrayList();
		for (User user : users) {
			ids.add(user.getId());
		}
		return Joiner.on(",").join(ids);
	}
}
